var introduction = new Vue({

    el:'#introduction',
    //初始化数据类型
    data:{
        type:0,
        //横向菜单
        crosswiseNav:[],
        //商品细节
        productDetail:[],
        //评价
        estimate:[],
        //产品
        product:{},
        //商品对应商家信息
        merchant:{},

        /*预警信息*/
        warn:[],
        //商品数量
        commodityNum:0,
        href:{
            href1:["../home/home.html"],
            href2:["../home/shopcart.html"]
        },
    },
    //提交时间方法
    methods:{
        //计算商品数量信息
        calculate:function (val) {
            var _this = this;
            if(val){
                _this.commodityNum = _this.commodityNum+1
            }else {
                _this.commodityNum = _this.commodityNum-1
            }
            if(_this.commodityNum<0){
                _this.commodityNum = 0;
            }
            debugger;
            _this.product.commodityNum = _this.commodityNum;
        },

        //加入购物车
        onTouchAdd:function(product){
            var _this = this;
            if(_this.type==0){
                _this.$message({
                    message: '警告哦，您未登录！',
                    type: 'warning'
                });
            }else{
            if(_this.merchant.type==0){
                _this.$message({
                    message: '警告哦，该商家未入围不能添加其商品至购物车！',
                    type: 'warning'
                });
            }else{
                if(product.install==0||product.install==2){
                    _this.$message({
                        message: '警告哦，该商品已下架不能添加至购物车！',
                        type: 'warning'
                    });
                }else{
                    $.post("/home/order_detail/insertShopCart",{"lim":JSON.stringify(_this.product), "sell":_this.merchant.type},function(data){
                        if(data.data.shopCart==1){
                            _this.$message({
                                message: '恭喜你，该商品已添加至购物车',
                                type: 'success'
                            });
                        }else{
                            _this.$message({
                                message: '警告哦，商品未添加至购物车',
                                type: 'warning'
                            });
                        }
                    });
                }
            }
            }
        },
        //进入店铺
        enterSell:function(merchant){
            var _this = this;
            $("#introduction").load("http://"+window.location.host+"/person/selldetail.html",function () {
                merchant.creationTime = moment().format("YYYY-MM-DD")
                selldetail.sellinformation = merchant;
                $.post("/home/commodity/selectCommodityByMerchant",{"id":merchant.id},function(data){
                    selldetail.product = data.data.commodityList;
                });
            });

        },
    },
    //页面加载后初始化方法
    created:function () {
        var  _this = this;
        //初始化横向菜单
        var crosswiseNavList = [
            {href:"../home/offers.html",name: "询价表", url: "#"},
            {href:"../home/quotation.html",name: "报价单", url: "#"},
        ];
        _this.crosswiseNav = crosswiseNavList;//后台动态添加进入
            //查看用户是否已经登录
        $.post("/home/dataCache/selectDataCache", "", function (data) {
            if(data.code == 200){
                _this.type = 1
            }

        });
        //评价信息
        $.post("/home/estimate/selectShop","",function(data){
            var estimates = data.data.estimates;
            var estimate = [];
            for(var i = 0;i<estimates.length;i++){
                if(_this.product.id == estimates[i].commodityId ){
                    estimate.push(estimates[i]);
                    _this.estimate = estimate;
                }
                //计算累计评价
                _this.product.evalusteNum = _this.estimate.length;
            }
        });
        //商家信息
        $.post("/home/merchant/selectAll", "", function (data) {
            var merchant = data.data.merchant;
            for(var i=0;i<merchant.length;i++){
                if(_this.product.businessesId==merchant[i].id){
                        _this.merchant=merchant[i];
                }
            }

        });

        //初始化产品细节
        var productDetailShow = new Array();
        productDetailShow.push("../lib/images/tw1.jpg");

        _this.productDetail = productDetailShow;

        //放大镜
        $(document).ready(function () {
            $(".jqzoom").imagezoom();
            $("#thumblist li a").click(function () {
                $(this).parents("li").addClass("tb-selected").siblings().removeClass("tb-selected");
                $(".jqzoom").attr('src', $(this).find("img").attr("mid"));
                $(".jqzoom").attr('rel', $(this).find("img").attr("big"));
            });
        });
        $(window).load(function () {
            $('.flexslider').flexslider({
                animation: "slide",
                start: function (slider) {
                    $('body').removeClass('loading');
                }
            });
        });
        //其它说明鼠标事件
        $(function(){
            $("#rests").hover(
                function(){
                    $("#title").fadeIn(200,function(){
                        $("#title").css("display","block");
                    });

            },
                function () {
                    $("#title").fadeIn(200,function(){
                        $("#title").css("display","none");
                    });
                });
        });
    }

});